package com.crazyread.dao;

import com.crazyread.model.domain.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {
   //查询某书下的所有评论
    @Select("select * from comment where book_id=#{bookId} order by id desc")
    public List<Comment> getCommentList(Integer bookId);
    //统计某书所有品论数量
    @Select("select count(1) from comment where book_id=#{bookId}")
    public Integer countComment(Integer bookId);
    //删除某条评论
    @Delete("delete from comment where id=#{id}")
    public Integer deleteCommentWithId(Integer id);
    //删除该书籍下所有评论
    @Delete("delete from comment where book_id=#{bookId}")
    public Integer deleteCommentByBookId(Integer bookId);
    //发表评论
    @Insert("INSERT INTO comment (book_id,created,username,content)"+
            "VALUES (#{bookId},#{created},#{username},#{content})")
    public void pushComment(Comment comment);

}
